package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Room;
import com.ruoyi.system.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 自习室Controller
 * 
 * @author ...
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/system/room")
public class RoomController extends BaseController
{
    @Autowired
    private IRoomService roomService;

    /**
     * 查询自习室列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Room room)
    {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }

    /**
     * 获取自习室详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(roomService.selectRoomById(id));
    }

    /**
     * 新增自习室
     */
    @PostMapping
    public AjaxResult add(@RequestBody Room room)
    {
        room.setCreateUser(SecurityUtils.getUserId().intValue());
        room.setCreateTime(DateUtils.getNowDate());
        return toAjax(roomService.insertRoom(room));
    }

    /**
     * 修改自习室
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Room room)
    {
        room.setUpdateUser(SecurityUtils.getUserId().intValue());
        room.setUpdateTime(DateUtils.getNowDate());
        return toAjax(roomService.updateRoom(room));
    }

    /**
     * 删除自习室
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(roomService.deleteRoomByIds(ids));
    }
}
